package com.ruoyi.control.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //添加
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.control.domain.Mainventilator1History;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.control.mapper.AircompressorHistoryMapper;
import com.ruoyi.control.domain.AircompressorHistory;
import com.ruoyi.control.service.IAircompressorHistoryService;

/**
 * 空压机历史数据Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-08
 */
@Service
public class AircompressorHistoryServiceImpl extends ServiceImpl<AircompressorHistoryMapper, AircompressorHistory> implements IAircompressorHistoryService //修改
{
    @Autowired
    private AircompressorHistoryMapper aircompressorHistoryMapper;

    /**
     * 查询空压机历史数据
     *
     * @param id 空压机历史数据主键
     * @return 空压机历史数据
     */
    @Override
    public AircompressorHistory selectAircompressorHistoryById(String id)
    {
        return aircompressorHistoryMapper.selectAircompressorHistoryById(id);
    }

    /**
     * 查询空压机历史数据列表
     *
     * @param aircompressorHistory 空压机历史数据
     * @return 空压机历史数据
     */
    @Override
    public List<AircompressorHistory> selectAircompressorHistoryList(AircompressorHistory aircompressorHistory)
    {
        return aircompressorHistoryMapper.selectAircompressorHistoryList(aircompressorHistory);
    }

    /**
     * 新增空压机历史数据
     *
     * @param aircompressorHistory 空压机历史数据
     * @return 结果
     */
    @Override
    public int insertAircompressorHistory(AircompressorHistory aircompressorHistory)
    {
        return aircompressorHistoryMapper.insertAircompressorHistory(aircompressorHistory);
    }

    /**
     * 修改空压机历史数据
     *
     * @param aircompressorHistory 空压机历史数据
     * @return 结果
     */
    @Override
    public int updateAircompressorHistory(AircompressorHistory aircompressorHistory)
    {
        aircompressorHistory.setUpdateTime(DateUtils.getNowDate());
        return aircompressorHistoryMapper.updateAircompressorHistory(aircompressorHistory);
    }

    /**
     * 批量删除空压机历史数据
     *
     * @param ids 需要删除的空压机历史数据主键
     * @return 结果
     */
    @Override
    public int deleteAircompressorHistoryByIds(String[] ids)
    {
        return aircompressorHistoryMapper.deleteAircompressorHistoryByIds(ids);
    }

    /**
     * 删除空压机历史数据信息
     *
     * @param id 空压机历史数据主键
     * @return 结果
     */
    @Override
    public int deleteAircompressorHistoryById(String id)
    {
        return aircompressorHistoryMapper.deleteAircompressorHistoryById(id);
    }

    @Override
    public Integer[] selectByTagName(String tagName) {
        Integer[] history= new Integer[60*24];
        List<AircompressorHistory> historyList=aircompressorHistoryMapper.selectByTagName(tagName);
        for (int i=0; i<60*24;i++){
            if (i>=historyList.size()){
                history[i]= 0;
            }else {
                double doubleValue = Double.parseDouble(historyList.get(i).getValue());
                int intValue = (int) doubleValue; // 如果需要四舍五入，可以使用 Math.round(doubleValue)
                history[i] = intValue;
            }
        }
        return history;
    }
}
